\chapter{Part A -- Formalizing the Wiki syntaks}

We have formalized the syntax of WikiXML using DTD and XML Schema. The resulting schemas are to be found in the files \texttt{WikiXML.dtd} and \texttt{WikiXML.xsd}. 

\section{Interpretting ambiguities in the informal description}

We are to identify ambiguities in the informal description of WikiXML and explain how we relate to them. The informal description taken completely literally contains no contradictions and it is principally possible to implement it. There are however some odd definitions. One of the restrictions in the description is that we are not allowed to have consecutive \texttt{word} elements. One would have to put another element in between, e.g. a \texttt{ws} element. This restriction makes sense since it is meaningless to speak of two \texttt{word} elements that are not separated. The restriction is odd however because we can separate \texttt{word} elements with other elements than \texttt{ws} elements, e.g. \texttt{bold} or \texttt{header} elements. 

Another odd definition is that of \texttt{header}. The intuition of \texttt{header} is that it is more basic than the other tags and stands on its own. Thus we would expect that \texttt{header} elements should not be contained in any other elements than \texttt{wiki}. At present it is legal for \texttt{header} elements to be children of \texttt{bold} and elements in a list. If we wanted bold text in the a header it is more intuitive to specify the \texttt{bold} tag \emph{inside} the \texttt{header} tag. 

One vague definition in the informal description is that of \texttt{word}. It doesn't really say how \texttt{word} should be defined, only that it contains character data and cannot have leading or trailing whitespaces. First of all the definition should say that whitespaces are not allowed inside the text body either. It doesn't really say which data should be allowed the the text body. Is for example \texttt{abc<bold>def</bold>ghi} legal as the interior of a \texttt{word} element. Our interpretation is that any unicode character other than whitespaces is allowed and that it is a matter of the parser to translate critical characters like \texttt{<}. In this view the text would be legal and will give the result: \texttt{<word>abc\&lt;bold\&gt;def\&lt;/bold\&gt;ghi</word>}, which is in agreement with the informal description of WikiXML.

\section{Explaining any discrepancies that may exist between the informal description and our schemas}

Creating our WikiXML schema we are carefull not to exclude any documents that are valid according to the informal description. That would mean we can not be sure that documents from an external source can be added to our server. There are however some restrictions we do not define in the schemas. This occurs when the repressentation of the restrictions are too complicated or there are some other inconveniences involved such as tedious maintainance. 

One of the restrictions we are not repressenting are the demand that \texttt{italics}, \texttt{tt} and \texttt{bold} cannot have elements of their own kind in their \texttt{descendant}-axis. We have chosen not to implement this restriction completely but will merely implement the restriction that \texttt{italics}, \texttt{tt} and \texttt{bold} cannot have elements of their own kind in their \texttt{child}-axis. A comlete implementation could be constructed by defining a number of \texttt{group} elements, namely 

\begin{enumerate}[A]
\item: anything but \texttt{italics}
\item: anything but \texttt{tt}
\item: anything but \texttt{bold}
\item: anything but \texttt{italics} and \texttt{tt}
\item: anything but \texttt{italics} and \texttt{bold}
\item: anything but \texttt{tt} and \texttt{bold}
\item: anything but \texttt{italics}, \texttt{tt} and \texttt{bold}
\end{enumerate}

We now set the content of \texttt{italics} to be A, the content of \texttt{tt} to be B and the content of \texttt{bold} to be C. In A we set the content of a \texttt{tt} element to be D, the content of a \texttt{bold} element to be E and the content of the rest of the elements to be A. In D we set the content of a \texttt{bold} element to be G and the content of the rest of the elements to be D. Likewise in E we set the content of a \texttt{tt} element to be G and the content of the rest of the elements to be E. Similar constructions are made for the content of B and C. 

With this construction we have made sure that \texttt{italics}, \texttt{tt} and \texttt{bold} cannot be nested. It is not a good solution though. The construction is complicated and is tedious to expand. In fact the number of groups introduced in the construction grows exponentially to the number of elements that may not be nested, which is unacceptable in almost any contexts. 

We conclude that this repressenting this restriction has a high cost and considering the context it isn't really valuable. When converting a textual Wiki-document to WikiXML this restriction rarely ever manifestes itself since it is not possible to nest \texttt{italics} and \texttt{bold} text in the textual repressentation. This is due to that the begin and end tags are the same, ie. \`{}\`{}\`{} and \`{}\`{}.

Another restriction we do not implement is that not two \texttt{word} or two \texttt{ws} elements may be adjacent in a sequence. Like the former restriction this can be solved by handling the different combinations of elements resulting in a complicated construction and it will never really realize itself. Parsing a textual Wiki-document to WikiXML two \texttt{word} elements are always separated e.g. by a \texttt{ws} element and successive whitespaces will probably collapse. The size of this construction will not grow exponentially though so it is manageable to implement and maintain.